



// MHNetwork.h: interface for the CMHNetwork class.
//
//////////////////////////////////////////////////////////////////////

#define SAFE_RELEASE(a)			if((a))	{ (a)->Release(); (a)=NULL; }
#pragma once
#include "basenetworkinterface.h"

class cMainState;
class CMHNetwork  
{
	BOOL m_bDisconnecting;
	HWND m_hMainWnd;

	ISC_BaseNetwork* m_pBaseNetwork;
	DWORD m_ConnectionIndex;
	cMainState* MyChat;
	DWORD m_RecvedDataSize;	
	DWORD m_RecvCount;
	BYTE m_CheckSum;
	cMainState* m_MianDlg;
public:
	void SetState(cMainState* t);
	void SetMainDlg(cMainState* t) { m_MianDlg = t; }
	static CMHNetwork& getinstance();
	CMHNetwork();
	virtual ~CMHNetwork();
	BOOL Init(HWND hWnd);
	void Release();

	BOOL ConnectToServer(char* ip,WORD port);
	void Disconnect();

	
	void Send(MSGROOT* pMsg,int MsgLen);

	BOOL IsConnected()	{	return m_ConnectionIndex ? TRUE : FALSE;	}
	
	ISC_BaseNetwork* GetBaseNetwork()							{ return m_pBaseNetwork; }
	friend void OnCon(DWORD dwConIndex);
	friend void OnDisCon(DWORD dwConIndex);
	friend void OnRecv(DWORD dwConIndex,char* pMsg,DWORD msglen);
};


#define sCMHNetwork CMHNetwork::getinstance()

